package com.heima.controller;

import com.heima.pojo.dto.VmTypeDto;
import com.heima.pojo.vo.VmTypeVo;
import com.heima.service.VmTypeService;
import com.heima.utils.PageResult;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author 赵超
 */
@RestController
@RequestMapping("/api/vm-service/vmType")
@AllArgsConstructor
public class VmTypeController {
    private VmTypeService vmTypeService;

    @GetMapping("/search")
    public PageResult<VmTypeVo> page(String name, Integer pageIndex, Integer pageSize) {
        return vmTypeService.page(name, pageIndex, pageSize);
    }

    @PostMapping
    public Boolean add(@RequestBody VmTypeDto vmTypeDto) {
        return vmTypeService.add(vmTypeDto) > 0;
    }

    @PutMapping("/{typeId}")
    public Boolean update(@PathVariable Integer typeId, @RequestBody VmTypeDto vmTypeDto) {
        return vmTypeService.update(typeId, vmTypeDto) > 0;
    }

    @DeleteMapping("/{typeId}")
    public Boolean delete(@PathVariable Integer typeId) {
        return vmTypeService.delete(typeId) > 0;
    }
}
